package com.huike.clues.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huike.clues.domain.SysDictType;
import com.huike.clues.mapper.SysDictTypeMapper;
import com.huike.clues.service.ISysDictTypeService;
import com.huike.common.core.domain.entity.SysDictTypeDTO;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService {

    @Autowired
    private SysDictTypeMapper sysDictTypeMapper;

    /**
     * 新增字典类型
     * @param dto
     * @return
     */
    @Override
    public void addDict(SysDictTypeDTO dto) {
        //创建一个字典对象接受dto
        SysDictType sysDictType = new SysDictType();
        sysDictType.setDictName(dto.getDictName());
        sysDictType.setDictType(dto.getDictType());
        sysDictType.setStatus(dto.getStatus());
        sysDictType.setRemark(dto.getRemark());
        //补充数据
        sysDictType.setCreateBy(SecurityUtils.getUsername());
        sysDictType.setCreateTime(LocalDateTime.now());
        //保存数据
        sysDictTypeMapper.insert(sysDictType);
    }

    /**
     * 修改字典
     * @param dictType
     * @return
     */
    @Override
    public void updateDictType(SysDictType dictType) {
        //创建一个字典对象
        SysDictType sysDictType = new SysDictType();
        //属性复制
        BeanUtils.copyBeanProp(sysDictType, dictType);
        sysDictType.setUpdateBy(SecurityUtils.getUsername());
        sysDictType.setUpdateTime(LocalDateTime.now());
        sysDictTypeMapper.updateById(sysDictType);
    }
}
